import java.util.*;

public class set {
    public static void main(String[] args) {
        //Set继承了Collection接口
        Set<String> set=new TreeSet<>();
        set.add("西游记");
        set.add("认知觉醒");
        set.add("骆驼祥子");
        set.add("西游记");
        //重复元素不被添加
        System.out.println(set.toString());
        System.out.println(set.contains("Sv"));
        //返回迭代器
        for (Iterator<String> iterator=set.iterator();iterator.hasNext();){
            String temp= iterator.next();
            System.out.println(temp);
        }
        System.out.println(set.size());
        System.out.println(set.isEmpty());
        int[]arr=new int[set.size()];
        for (int i = 0; i <set.size() ; i++) {
            System.out.println(set);
        }

        String []arr1={"西游记","认知觉醒","骆驼祥子","红楼梦"};
        //判断结合arr1中的元素在set中是否存在
        System.out.println(set.containsAll(Arrays.asList(arr1)));
        System.out.println();
        for (int i = 0; i <arr1.length ; i++) {
            //判断set中是否含有arr1[i]元素  且将set不含的元素添加进去
            System.out.println(set.addAll(Collections.singleton((arr1[i]))));
        }
        System.out.println(set.toString());
        set.remove("西游记");
        System.out.println(set.toString());
        //清空元素
        set.clear();
        System.out.println(set.toString());
    }
}
